package com.douwong.student.fragment;

import android.annotation.SuppressLint;

import com.douwong.student.activity.ClassTestActivity;
import com.douwong.student.application.BaseApplication;
import com.douwong.student.base.BaseChoiceFragment;
import com.douwong.student.interfaces.ClassTestInterface;
import com.douwong.student.model.ResTestProblemsInfo;
import com.douwong.student.model.TestInfos;

/**
 * @autor yichao
 * @time 2017/4/516:05
 * @des ${TODO}
 */
@SuppressLint("ValidFragment")
public class SingleChoiceFrgment extends BaseChoiceFragment implements ClassTestInterface {
    private String chooseLastAnswer="";

    public SingleChoiceFrgment(ClassTestActivity classTestActivity, ResTestProblemsInfo.TopicItemBean topicItemBean) {
            super(classTestActivity,topicItemBean);
    }
    @Override
    protected void setSlectViewState(String str) {
        for (int i = 0; i < linearlayouts.length; i++) {
            if (str.equals(chart[i])) {
                if (mContenView.findViewById(linearlayouts[i]).isSelected()) {
                    mContenView.findViewById(linearlayouts[i]).setSelected(false);
                    chooseLastAnswer="";
                } else {
                    mContenView.findViewById(linearlayouts[i]).setSelected(true);
                    chooseLastAnswer = str;
                }
            } else {
                mContenView.findViewById(linearlayouts[i]).setSelected(false);
            }
        }

    }

    @Override
    public TestInfos getAnswerInfo() {
        TestInfos testInfos;
        if (chooseLastAnswer.equals("")){
            testInfos=new TestInfos(mTopicItemBean.getId(),0,new String[]{chooseLastAnswer});
            BaseApplication.noDoTestSum++;

        }else {
            double sore=0;
            if (chooseLastAnswer.equals(mTopicItemBean.getAnswers().get(0))){
                sore=mTopicItemBean.getScore();
            }
            testInfos=new TestInfos(mTopicItemBean.getId(),sore,new String[]{chooseLastAnswer});

        }
        return testInfos ;
    }

    @Override
    public void setCommitStatue() {
        for (int i = 0; i < linearlayouts.length; i++) {
            mContenView.findViewById(linearlayouts[i]).setClickable(false);
        }
    }
}
